// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Sender.java

package com.crm.sms;

import java.io.*;
import java.net.*;

public class Sender
{

	private String comName;
	private String comPwd;
	private String Server;

	public Sender()
	{
		this("default", "default");
	}

	public Sender(String name, String pwd)
	{
		comName = name;
		comPwd = pwd;
		Server = "http://www.china-sms.com";
	}

	public Sender(String name, String pwd, int serverNum)
	{
		comName = name;
		comPwd = pwd;
		if (serverNum == 2)
			Server = "http://www6.china-sms.com";
		else
			Server = "http://www.china-sms.com";
	}

	public String massSend(String dst, String msg, String time, String subNo)
	{
		String sUrl = null;
		try
		{
			sUrl = (new StringBuilder(String.valueOf(Server))).append("/send/gsend.asp?name=").append(comName).append("&pwd=").append(comPwd).append("&dst=").append(dst).append("&msg=").append(URLEncoder.encode(msg, "GB2312")).append("&time=").append(time).append("&sender=").append(subNo).toString();
		}
		catch (UnsupportedEncodingException uee)
		{
			System.out.println(uee.toString());
		}
		return getUrl(sUrl);
	}

	public String readSms()
	{
		String sUrl = null;
		sUrl = (new StringBuilder(String.valueOf(Server))).append("/send/readsms.asp?name=").append(comName).append("&pwd=").append(comPwd).toString();
		try
		{
			URLEncoder.encode(sUrl, "GB2312");
		}
		catch (UnsupportedEncodingException uee)
		{
			System.out.println(uee.toString());
		}
		return getUrl(sUrl);
	}

	public String getFee()
	{
		String sUrl = null;
		sUrl = (new StringBuilder(String.valueOf(Server))).append("/send/getfee.asp?name=").append(comName).append("&pwd=").append(comPwd).toString();
		return getUrl(sUrl);
	}

	public String changePwd(String newPwd)
	{
		String sUrl = null;
		sUrl = (new StringBuilder(String.valueOf(Server))).append("/send/cpwd.asp?name=").append(comName).append("&pwd=").append(comPwd).append("&newpwd=").append(newPwd).toString();
		try
		{
			URLEncoder.encode(sUrl, "GB2312");
		}
		catch (UnsupportedEncodingException uee)
		{
			System.out.println(uee.toString());
		}
		return getUrl(sUrl);
	}

	public String getUrl(String urlString)
	{
		StringBuffer sb = new StringBuffer();
		try
		{
			URL url = new URL(urlString);
			URLConnection conn = url.openConnection();
			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			for (String line = null; (line = reader.readLine()) != null;)
				sb.append((new StringBuilder(String.valueOf(line))).append("\n").toString());

			reader.close();
		}
		catch (IOException e)
		{
			System.out.println(e.toString());
		}
		return sb.toString();
	}
}
